import * as storage from '@/util/storage.js';

function isExist({ arg, value }) {
  const MenuVOList = R.compose(
    R.propOr([], 'menuVOList'),
    storage.readAsObj,
  );

  const FuncList = R.compose(
    R.propOr([], 'funcList'),
    R.find(R.where({ routeKey: R.includes(arg) })),
  );

  const ExpectedFn = R.find(R.where({
    functionName: R.equals(value),
    needShow: Boolean,
  }));

  return R.compose( ExpectedFn, FuncList, MenuVOList )('userInfo');
}


export const vExist = {
  mounted(elem, binding, vnode, prevVnode) {
    // 若在指定路由找到期望中的功能，则显示元素
    !isExist(binding) && elem.remove();
  },
};
